package com.atguigu.zy.interview.juc.locks;

import java.util.concurrent.*;

/**
 * @Author : Jungle
 * @Description :
 */
public class ThreadPoolDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        /**
         * 1、int corePoolSize,
         *                               int maximumPoolSize,
         *                               long keepAliveTime,
         *                               TimeUnit unit,
         *                               BlockingQueue<Runnable> workQueue,
         *                               ThreadFactory threadFactory,
         *                               RejectedExecutionHandler handler
         */
        ExecutorService pool = new ThreadPoolExecutor(10, 32, 10, TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(100),Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());
        //CountDownLatch countDownLatch = new CountDownLatch(100);
        FutureTask<String> task = null;
        for (int i = 0; i < 100; i++) {
            int finalI = i;
            task = new FutureTask<>(() -> {
                System.out.println(Thread.currentThread().getName() + "\t 卖完第" + (finalI + 1) + "\t 张票");
                return "100张车票全部卖完";
            });
            pool.submit(task);
        }
        System.out.println(task.get());
        pool.shutdown();

    }
}
